<template>
    <div>
        <div v-for="item in comments" class="author-title">
            <el-avatar class="header-img" :size="40" :src="item.userImageAddress ?? basePhoto"></el-avatar>
            <div class="author-info">
                <span class="author-name">{{ item.userName ?? item.notificationTitle }}</span>
                <span class="author-time">{{ item.createTime ?? item.notificationCategory }}</span>
            </div>
            <div class="icon-btn" v-if="'likeSize' in item">
                <span @click="showReplyInput(item)">
                    <i class="iconfont icon-good" :style="{ color: item.likeStatus ? 'red' : '' }"></i>
                    {{ item.likeSize }}
                </span>
                <span @click="sendComment(item)"><i class="el-icon-chat-dot-square"></i></span>
            </div>
            <div class="talk-box">
                <p>
                    <span class="reply">{{ item.commentContent ?? item.notificationContent }}</span>
                </p>
            </div>
            <div class="reply-box">
                <div v-for="value in item.commentList" class="author-title">
                    <el-avatar class="header-img" :size="40" :src="value.userImageAddress"></el-avatar>
                    <div class="author-info">
                        <span class="author-name">{{ value.userName }}</span>
                        <span class="author-time">{{ value.createTime }}</span>
                    </div>
                    <div class="icon-btn" v-if="'likeSize' in item" @click="showReplyInput(value)">
                        <i class="iconfont icon-good" :style="{ color: value.likeStatus ? 'red' : '' }"></i>
                        {{ value.likeSize }}
                    </div>
                    <div class="talk-box">
                        <p>
                            <span class="reply">{{ value.commentContent }}</span>
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import morentupian from '@/assets/morentupian.jpg'
import { like } from '@/api/video'
export default {
    props: ['comments'],
    data() {
        return {
            basePhoto: morentupian,
            btnShow: false
        }
    },
    methods: {
        showReplyBtn() {
            this.btnShow = true
        },
        hideReplyBtn() {
            this.btnShow = false
            replyInput.style.padding = "10px"
            replyInput.style.border = "none"
        },
        showReplyInput(value) {
            let data = {
                commentId: value.commendId,
                commentType: value.commendType,
                Status: (value.likeStatus + 1) % 2
            }
            if (this.$store.getters.token.userId) {
                data.userId = this.$store.getters.token.userId
            } else {
                this.$router.push({ path: '/' })
            }
            like(data).then(res => {
                this.$message(res.errorMessage)
                this.$emit('getCommit')
            })
        },
        sendComment(value) {
            this.$emit('sonSendComment', value)
        }
    },
}
</script>

<style scoped>
.my-comment-reply {
    margin-left: 50px;
}

.my-comment-reply .reply-input {
    width: flex;
}

.author-title:not(:last-child) {
    border-bottom: 1px solid rgba(178, 186, 194, 0.3);
}

.author-title {
    padding: 10px;
}

.author-title .header-img {
    display: inline-block;
    vertical-align: top;
}

.author-title .header-img::v-deep img {
    width: 100%;
    height: 100%;
}

.author-title .author-info {
    display: inline-block;
    margin-left: 5px;
    width: 60%;
    height: 40px;
    line-height: 20px;
}

.author-title .author-info>span {
    display: block;
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.author-title .author-info .author-name {
    color: #000;
    font-size: 18px;
    font-weight: bold;
}

.author-title .author-info .author-time {
    font-size: 14px;
}

.author-title .icon-btn {
    width: 30%;
    padding: 0 !important;
    float: right;
}

.author-title .icon-btn>span {
    margin-right: 60px;
}

@media screen and (max-width: 1200px) {
    .author-title .icon-btn {
        width: 20%;
        padding: 7px;
    }
}

.author-title .icon-btn>span {
    cursor: pointer;
}

.author-title .icon-btn .iconfont {
    margin: 0 5px;
}

.author-title .talk-box {
    margin: 0 50px;
}

.author-title .talk-box>p {
    margin: 0;
}

.author-title .talk-box .reply {
    font-size: 16px;
    color: #000;
}

.author-title .reply-box {
    margin: 10px 0 0 50px;
    background-color: #efefef;
}
</style>